export function delay(time) {
    return new Promise(function (resolve) {
        setTimeout(resolve, time)
    });
}

export async function autoScrollZero(page, distance = 100) {
    await page.evaluate(async ({ distance }) => {
        await new Promise((resolve, reject) => {
            let scrollHeight = document.body.scrollHeight;
            var totalHeight = scrollHeight;
            var timer = setInterval(([distanceTime, scrollHeightTime]) => {
                window.scrollBy(0, -distanceTime);
                totalHeight -= distanceTime;
                if (totalHeight <= 0) {
                    clearInterval(timer);
                    resolve();
                }
            }, 100, [distance, scrollHeight]);
        });
    }, { distance });
}